<template>
  <view class="container">
    <!-- 显示二维码的地方 -->
    <image class="qr" :src="base64Image" v-if="base64Image"></image>
  </view>
</template>

<script>
  import {
    getqrcode
  } from '../../api/qr/qr.js'
  export default {
    data() {
      return {
        base64Image: '',
        qrcodeText: '',
		access_token :'',
		loading:false
      }
    },
    onLoad() {
      
    },
	onShow() {
		this.getqrcode()
		uni.showLoading({
			title: '分享码加载中',
			mask: true
		});
	},
    methods: {
      getqrcode() {
        let data = {
          userId: uni.getStorageSync('userInfo').userId,
        }
        getqrcode(data).then(res => {
			//  console.log(res);
			if(res.statusCode!=200){
				uni.showToast({
					title: "分享码获取失败，请稍后重试",
					icon: 'none',
					})
					return;
			}
          //  console.log(res.data.data.qrcodeText)
		  let base64 = res.data.data.base64;
		  base64 = 'data:image/png;base64,' + base64; // 拼接 base64 数据头
		  this.base64Image = base64; // 设置为 base64Image 变量
		  uni.hideLoading();
        }).catch(err=>{
				//  console.log(err)
				this.loading = false
				uni.showToast({
					title: "分享码获取失败，请稍后重试\n"+err.data.message,
					icon: 'none',
					})
		})

      },

    }
  }
</script>

<style>
  .container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #04be02;
  }

  .qr {
    background-color: red;
    height: 250px;
    width: 250px;
    /* 阴影 */
    box-shadow: 0 0 10px #000;
    border-radius: 10px;
  }
</style>